package com.dminvoicemanager;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.HttpResponseException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONStringer;

import com.dminvoicemanager.itemmaster.DM_Item_Master;
import com.dminvoicemanager.itinerary.DM_Itinerary_Report_Main;
import com.dminvoicemanager.reports.DM_Sales_Summary_Report;

import android.R.integer;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.WebChromeClient.CustomViewCallback;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class DM_Day_Summary extends Activity {

	// private PBDatabaseAdapter dbHelper;
	ProgressDialog mProgressDialog;
	private String DBNAME = "dminvoicemanager.db";
	// Master Tables
	private String SERVER_DB_LIST = "serverdb";
	private String USER_SETTINGS = "usersettings";
	private String ITEM_AREA = "fArea";
	private String ITEM_COMPANY_SETTING = "fCompanySetting";
	private String ITEM_CONTROL = "fControl";
	private String ITEM_DEBTOR = "fDebtor";
	private String ITEM_LOC_DETAILS = "fItemLoc";
	private String ITEM_LOCATION = "fLocation";
	private String ITEM_PRICE = "fItemPri";
	private String ITEMS = "fItems";
	private String INV_COMPANY_BRANCH = "FCompanyBranch";
	private String INV_SAL_REP = "fSalRep";
	private String SALES_ORD_REASON = "fReason";
	private String SALES_REP_ROUTE = "fRoute";
	private String BANK_DETAILS = "fBank";
	private String USER_EXPENSE = "fExpense";
	private String TOWN_DETAILS = "fTown";
	private String MERCH_DETAILS = "FMerch";

	// Main Invoice
	private String TEMP_REP_INVOICESUMERY = "frepInvoiceSumery";
	private String INV_DETAILS = "FinvDet";
	private String INV_HEADER = "FinvHed";

	// Stock Loading
	private String TEMP_STOCK_LOADING_SUMMARY = "frepStockLoadingSummary";
	private String STOCK_LOAD_HEAD = "fLoadhed";
	private String STOCK_LOAD_DETAIL = "fLoadDet";

	// Sales Order
	private String STOCK_ORDER_INVOICESUMERY = "fstockordInvoiceSumery";
	private String STOCK_ORDER_HEAD = "FOrdHed";
	private String STOCK_ORDER_DETAIL = "FOrddet";
	private String TEMPSTOCK_ORDER_HEAD = "TempFOrdHed";
	private String TEMPSTOCK_ORDER_DETAIL = "TempFOrddet";

	// Stock UnLoading
	private String TEMP_STOCK_LOADING_SUMMARYUN = "frepStockLoadingSummaryUn";
	private String STOCK_LOAD_HEADUN = "fUnLoadhed";
	private String STOCK_LOAD_DETAILUN = "fUnLoadDet";

	// Stock Damage
	private String TEMP_STOCK_LOADING_SUMMARYDAM = "frepStockLoadingSummaryDam";
	private String STOCK_LOAD_HEADDAM = "fDamhed";
	private String STOCK_LOAD_DETAILDAM = "fDamdet";

	// Cash /Receipt header
	private String TEMP_RECEIPT_SUMMARY = "fReceiptSummary";
	private String RECEIPT_HEADER = "fDRecHed";
	private String RECEIPT_DETAILS = "fDRecDet";

	// Adjustment
	private String TEMP_ADJUSTMENT_SUMMARY = "FAdjustmentSummary";
	private String ADJUST_ADDITION_HEADER = "FAdjHed";
	private String ADJUST_ADDITION_DETAILS = "FAdjDet";

	// Expense
	private String TEMP_DAYEXPENSE_SUMMARY = "FDayExpSummary";
	private String DAYEXPENSE_HEADER = "FDayExpHed";
	private String DAYEXPENSE_DETAILS = "FDayExpDet";

	private String RECEIPT_INVOICES = "FDDbNote";

	// None Productive Calls
	private String DAILY_NONE_PRDCALLS_HEAD = "fNonePrd";

	private SQLiteDatabase mydb;
	final private static int DIALOG_SYNC_DATA = 1;
	final private static int DIALOG_UPLOADING_DATA = 2;
	int count = 0;
	int countdet = 0;
	JSONArray jArray, jArrayp;
	String result = null;
	String resultp = null;
	InputStream is = null;
	InputStream isp = null;
	StringBuilder sb = null;
	StringBuilder sbp = null;
	int newinvNo;
	String Tagid, currentUserTemp, currentUserPrefix, UserLocCode, RepInvCode,
			TransTypePrefix, AgentPrefixType, currentUserServerDB,
			serverSynchDbName, CurrentAdjLocation, AgentDealCode, serverDbName,UserRouteCode;
	AlertDialog SynchDetails = null;
	int lastId,lastId1,lastId2,lastId3,lastId4,lastId5,lastId6,lastId7,lastId8,lastId9,lastId10;
	String strlastId, TagId,strlastId1,strlastId2,strlastId3,strlastId4,strlastId5,strlastId6,strlastId7,strlastId8,strlastId9,strlastId10;
	int CHKSTORDTAG = 0;
	String match = "5";
	String FInvHedIndex, FInvDetIndex, FUnloadHedIndex, FReceiptHedIndex,
			FStlDamHedIndex, FStoOrdersHedIndex, FStoUnloadDetIndex,
			FReceiptDetIndex, FDamageDetIndex, FStOrderDetIndex, txtDate;
	double DiscountAmt = 0.0,InvoicAmt =0.0 ,SalesAmt =0.0 ,CheqAmt=0.0,CashAmt=0.0;
	DecimalFormat formatValues = new DecimalFormat("#,###,##0.00");

	/* AlertDialog UploadingDetails = null; */
	SimpleDateFormat originalFormat = new SimpleDateFormat("dd MM yyyy");
	SimpleDateFormat targetFormat = new SimpleDateFormat("yyyy-MM-dd");
	Date date;

	TextView txtCallCount,txtCallLost,txtSalInvCount,txtSalOrdCount,txtSalInvAmt,txtSalOrdAmt,txtPayCashCount,txtPayCashAmt,
	         txtPayCheqCount,txtPayCheqAmt,txtReUseCs,txtReUsePs,txtMktPc,txtMktCs,txtFreeIssCs,txtFreeIssPs,txtDiscount,txtProductivePresentage,
	         txtProductive,txtCallCountSO,txtSalOrdCountSO,txtProductiveSO,txtProductivePresentageSO;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dm_day_summary);

		txtCallCount = (TextView) findViewById(R.id.dmCallCountComp);
		txtCallCountSO = (TextView) findViewById(R.id.dmCallCountCompSO);
		txtCallLost =  (TextView) findViewById(R.id.dmCallCountLost);
		txtSalInvCount =  (TextView) findViewById(R.id.dmSalesInvCount);
		txtSalOrdCount =  (TextView) findViewById(R.id.dmSaleOrdCount);
		txtSalOrdCountSO =  (TextView) findViewById(R.id.dmCallCountLostSO);
		txtSalInvAmt =  (TextView) findViewById(R.id.dmSalesInvAmt);
		txtSalOrdAmt =  (TextView) findViewById(R.id.dmSaleOrdAmt);
		txtPayCashCount =(TextView) findViewById(R.id.dmPayCashCount); 
		txtPayCashAmt =(TextView) findViewById(R.id.dmPayCashAmt);
		txtPayCheqCount =(TextView) findViewById(R.id.dmPayChqCount);
		txtPayCheqAmt =(TextView) findViewById(R.id.dmPayChqAmount);
		txtReUseCs = (TextView) findViewById(R.id.dmstUseRetCs);
		txtReUsePs = (TextView) findViewById(R.id.dmstUseRetPs);
		txtMktCs = (TextView) findViewById(R.id.dmstMarketRetCs);
		txtMktPc = (TextView) findViewById(R.id.dmstMarketRetPs);
		txtFreeIssCs = (TextView) findViewById(R.id.dmstFreeIsuCs);
		txtFreeIssPs =  (TextView) findViewById(R.id.dmstFreeIsuPs);
		txtDiscount =   (TextView) findViewById(R.id.dmstDisountAmt);
		txtProductive = (TextView) findViewById(R.id.dmCallCountProductive);
		txtProductiveSO = (TextView) findViewById(R.id.dmCallCountProductiveSO);
		txtProductivePresentage = (TextView) findViewById(R.id.dmProductivePresentage);
		txtProductivePresentageSO = (TextView) findViewById(R.id.dmProductivePresentageSO);

		
		currentuserTemp1();
		getInvoice();
		GetAmt();
		
	}
	
	
	private void getInvoice(){
		 
		txtDate = getCurrentTimeString().toString(); 
		Log.v("", "Date / Date -::" + txtDate + ":"+ txtDate);
		
		SQLiteDatabase mydb;
		mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE, null);
		Cursor allrowitemsdes = null; // debtor list
		Cursor allrowitemsdes2 = null; // invoice list
		Cursor allrowfinvhed = null; //invoice list
		Cursor allrowfordhed = null; //order list
		Cursor allrowfpayhedCash = null; //payCash list
		Cursor allrowfpayhedChq = null; //payChq list
		Cursor allrowFNonePrdNP = null; //NonePrd NP list
		Cursor allrowfordhedSO = null; //order listSO

		
		
		allrowitemsdes2 = mydb.query(INV_HEADER, null,"txndate='" + txtDate + "' AND invhedSync <> 3 ", null,
				null, null, null);
		
		String DebcodeStr= "SELECT RD.DebCode,RD.RouteCode,FD.DebName,FD.OutDis FROM fRouteDet RD,fDebtor FD Where FD.DebCode = RD.DebCode AND RD.RouteCode ='"
				+ UserRouteCode + "'";
		allrowitemsdes = mydb.rawQuery(DebcodeStr, null);
//		allrowitemsdes = mydb.query(ITEM_DEBTOR, null, null, null, null,
//				null, null);
		
		allrowfordhed = mydb.query(STOCK_ORDER_HEAD, null, "txndate='" + txtDate + "' AND stOrdhedSync <> 3", null, null,
				null, null);
		
		allrowfpayhedCash = mydb.query(RECEIPT_HEADER, null, "Paytype='CA' AND txndate='" + txtDate + "'", null, null,
				null, null);
		
		allrowfpayhedChq = mydb.query(RECEIPT_HEADER, null, "Paytype='CH' AND txndate='" + txtDate + "'", null, null,
				null, null);
		
		allrowFNonePrdNP = mydb.query(DAILY_NONE_PRDCALLS_HEAD, null, "Status='NP' AND txndate='" + txtDate + "'", null, null,
				null, null);

		
		try {
			String query = "SELECT  debcode,COUNT(debcode) FROM FinvHed where txndate='" + txtDate + "' group by debcode"; //finvhed debcode
	     	allrowfinvhed = mydb.rawQuery(query, null);
		} catch (Exception e1) {
		}
		
		int CallCount = allrowitemsdes2.getCount();
		int CallLost = allrowitemsdes.getCount();
		int callNewCount  = allrowfinvhed.getCount();
		int CallComp = CallLost - callNewCount;
		int SalInvOrdCount = allrowfordhed.getCount();
		int PayCashCount = allrowfpayhedCash.getCount();
		int PayChqCount = allrowfpayhedChq.getCount();
		int CountNP = allrowFNonePrdNP.getCount();
		
		int TotalVisit = CallCount + CountNP;
		
		//int ProdctPresent = (CallCount/CallLost);
		
	//	int ProdctPresent = (int)(((double)CallCount/(double)CallLost) * 100);
		
		double ProdctPresent = (double)(((double)CallCount/(double)CallLost) * 100);
		
		double ProdctPresentSO = (double)(((double)SalInvOrdCount/(double)CallLost) * 100);

		
		
		String str = Integer.toString(CallCount);
		String strInvCount = Integer.toString(callNewCount);
		String strLost = Integer.toString(CallComp);
		String strSalInvCount = Integer.toString(SalInvOrdCount);
		String strPayCashCount = Integer.toString(PayCashCount);
		String strPayChqCount = Integer.toString(PayChqCount);
		String strTotalVisit = Integer.toString(TotalVisit);
		String strTotalDebtor =  Integer.toString(CallLost);
	//	String strProductPresent =  Integer.toString(ProdctPresent);
	//	String strProductPresent =  new Double(ProdctPresent).toString();
		
		String strProductPresent = String.format("%.2f", ProdctPresent);
		
		String strProductPresentSO = String.format("%.2f", ProdctPresentSO);


		
		
		Log.v("", "count2 / countInvoiceHed -::" + callNewCount + ":"+ callNewCount);
		Log.v("", "count2 / countDebtor -::" + CallLost + ":"+ CallLost);
		Log.v("", "TotalVisited -::" + TotalVisit + ":"+ strTotalVisit);
		Log.v("", "Product Presentage -::" + strProductPresent + ":"+ strProductPresent);
		
		txtCallCount.setText(strTotalDebtor);
		txtCallLost.setText(strTotalVisit);
		txtSalInvCount.setText(str);
		txtSalOrdCount.setText(strSalInvCount);
		txtPayCashCount.setText(strPayCashCount);
		txtPayCheqCount.setText(strPayChqCount);
		txtProductive.setText(str);
		txtProductivePresentage.setText(strProductPresent);
		txtCallCountSO.setText(strTotalDebtor);
		txtSalOrdCountSO.setText(strSalInvCount);
		txtProductiveSO.setText(strSalInvCount);
		txtProductivePresentageSO.setText(strProductPresentSO);
		
		
		allrowitemsdes.close();
		allrowfinvhed.close();
		allrowfpayhedChq.close();
		allrowfpayhedCash.close();
		
		mydb.close();
	}
	
	private void GetAmt(){
		
		
		txtDate = getCurrentTimeString().toString(); 
		SQLiteDatabase mydb;
		mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE, null);
		
		Cursor allrowfordhed = null; //order list
		Cursor allrowfinvhed = null; //invoice list
		Cursor allrowfdreched = null; //rec cash list
		Cursor allrowfdrechedchq = null; //rec cash list
		Cursor allrowfinvhedReUseCs = null; //Re_Use_Ret list in Cases
		Cursor allrowfinvhedReUsePs = null; //Re_Use_Ret list in Ps
		Cursor allrowfinvhedMktUseCs = null; //Market_Ret list in Cs
		Cursor allrowfinvhedMktUsePs = null; //Market_Ret list in Ps
		Cursor allrowfinvhedFreeIssuCs = null; //Free Issue list in Cs
		Cursor allrowfinvhedFreeIssPs = null; //Free Issue list in Ps
		Cursor allrowfinvhedDiscount = null; //Finvdet Discount in all
		
		
		try {

			String query = "SELECT  SUM(cast(REPLACE (totalamt,',','')as float))  FROM FOrdHed WHERE txndate='" + txtDate + "'  AND stOrdhedSync <> 3";
			allrowfordhed = mydb.rawQuery(query, null);
	
			String query1 = "SELECT SUM(cast(REPLACE (totalamt,',','')as float)) FROM Finvhed WHERE txndate='" + txtDate + "'  AND invhedSync <> 3";
			allrowfinvhed = mydb.rawQuery(query1, null);
		
			String query2 = "SELECT SUM(cast(REPLACE (b.amt,',','')as float)) FROM Fdreched as a,Fdrecdet as b WHERE a.Paytype='CA' AND a.refno=b.refno AND a.txndate='" + txtDate + "'";
			allrowfdreched = mydb.rawQuery(query2, null);
	
			String query3 = "SELECT SUM(cast(REPLACE (b.amt,',','')as float)) FROM Fdreched as a,Fdrecdet as b WHERE a.Paytype='CH' AND a.refno=b.refno AND a.txndate='" + txtDate + "'";
			allrowfdrechedchq = mydb.rawQuery(query3, null);
			
			String query4 = "SELECT SUM(cast((CaseQty)as integer)) FROM Finvdet WHERE type='UR' AND txndate='" + txtDate + "' AND invdetSync <> 3";
			allrowfinvhedReUseCs = mydb.rawQuery(query4, null);
			
			String query5 = "SELECT SUM(cast((PiceQty)as integer)) FROM Finvdet WHERE type='UR' AND txndate='" + txtDate + "' AND invdetSync <> 3";
			allrowfinvhedReUsePs = mydb.rawQuery(query5, null);
			
			//String query6 = "SELECT SUM(cast((PiceQty)as integer)) FROM Finvdet WHERE type='MR' AND txndate='" + txtDate + "'";
			String query6 = "SELECT SUM(PiceQty) FROM Finvdet WHERE type='MR' AND txndate='" + txtDate + "' AND invdetSync <> 3";
			allrowfinvhedMktUsePs  = mydb.rawQuery(query6, null);
			
			String query7 = "SELECT SUM(cast((CaseQty)as integer)) FROM Finvdet WHERE type='MR' AND txndate='" + txtDate + "' AND invdetSync <> 3";
			allrowfinvhedMktUseCs = mydb.rawQuery(query7, null);
			
			String query8 = "SELECT SUM(cast((CaseQty)as integer)) FROM Finvdet WHERE type='FI' AND txndate='" + txtDate + "' AND invdetSync <> 3";
			allrowfinvhedFreeIssuCs  = mydb.rawQuery(query8, null);
			
			String query9 = "SELECT SUM(cast((PiceQty)as integer)) FROM Finvdet WHERE type='FI' AND txndate='" + txtDate + "' AND invdetSync <> 3";
			allrowfinvhedFreeIssPs = mydb.rawQuery(query9, null);
			
			String query10 = "SELECT SUM(cast(REPLACE (totaldis,',','')as float)) FROM Finvhed WHERE txndate='" + txtDate + "' AND invhedSync <> 3";
			allrowfinvhedDiscount = mydb.rawQuery(query10, null);
			
			
		} catch (Exception e1) {
		}
		
		if (allrowfordhed != null && allrowfordhed.moveToLast()) {
	
			float lastIdf =allrowfordhed.getFloat(0);
			strlastId = Float.toString(lastIdf);
			
		}
		
		if (allrowfinvhed != null && allrowfinvhed.moveToLast()) {
			float SalesAmtf = allrowfinvhed.getFloat(0);
			 strlastId1 = Float.toString(SalesAmtf);
			
		}
		
		if (allrowfdreched != null && allrowfdreched.moveToLast()) {
			float CashAmtf = allrowfdreched.getFloat(0);
			 strlastId2 = Float.toString(CashAmtf);
			
		}
		
		if (allrowfdrechedchq != null && allrowfdrechedchq.moveToLast()) {
			float CheqAmtf = allrowfdrechedchq.getFloat(0);
			 strlastId3 = Float.toString(CheqAmtf);
			
		}
		
		if (allrowfinvhedReUseCs != null && allrowfinvhedReUseCs.moveToLast()) {
			 lastId4 = allrowfinvhedReUseCs.getInt(0);
			 strlastId4 = Integer.toString(lastId4);
			
		}
		
		if (allrowfinvhedReUsePs != null && allrowfinvhedReUsePs.moveToLast()) {
			 lastId5 = allrowfinvhedReUsePs.getInt(0);
			 strlastId5 = Integer.toString(lastId5);
			
		}
		
		if (allrowfinvhedMktUseCs != null && allrowfinvhedMktUseCs.moveToLast()) {
			 lastId6 = allrowfinvhedMktUseCs.getInt(0);
			 strlastId6 = Integer.toString(lastId6);
			
		}
		
		if (allrowfinvhedMktUsePs != null && allrowfinvhedMktUsePs.moveToLast()) {
			 lastId7 = allrowfinvhedMktUsePs.getInt(0);
			 strlastId7 = Integer.toString(lastId7);
			
		}
		
		if (allrowfinvhedFreeIssuCs != null && allrowfinvhedFreeIssuCs.moveToLast()) {
			 lastId8 = allrowfinvhedFreeIssuCs.getInt(0);
			 strlastId8 = Integer.toString(lastId8);
			
		}
		
		if (allrowfinvhedFreeIssPs != null && allrowfinvhedFreeIssPs.moveToLast()) {
			 lastId9 = allrowfinvhedFreeIssPs.getInt(0);
			 strlastId9 = Integer.toString(lastId9);
			
		}
		
		if (allrowfinvhedDiscount != null && allrowfinvhedDiscount.moveToLast()) {
			float DiscountAmtf = allrowfinvhedDiscount.getFloat(0);
			 strlastId10 = Float.toString(DiscountAmtf);
			
		}

		Log.v("", "TotAmtOrd / TotAmtOrd -::" + strlastId2 + ":"+ strlastId2);
		txtSalInvAmt.setText(strlastId1);
		txtSalOrdAmt.setText(strlastId);
		txtPayCashAmt.setText(strlastId2);                           
		txtPayCheqAmt.setText(strlastId3);
		txtReUseCs.setText(strlastId4);
		txtReUsePs.setText(strlastId5);
		txtMktCs.setText(strlastId6);
		txtMktPc.setText(strlastId7);
		txtFreeIssCs.setText(strlastId8);
		txtFreeIssPs.setText(strlastId9);
		txtDiscount.setText(strlastId10);
		
		allrowfordhed.close();
		allrowfinvhed.close();
		allrowfdreched.close();
		allrowfinvhedMktUseCs.close();
		allrowfinvhedMktUsePs.close();
		allrowfinvhedReUseCs.close();
		allrowfinvhedReUsePs.close();
		allrowfinvhedFreeIssPs.close();
		allrowfinvhedFreeIssuCs.close();
		allrowfinvhedDiscount.close();
		mydb.close();
		
	}
	
	
	public void btnBack(View view) {
		Intent myIntent = new Intent(view.getContext(), DM_InvoiceMenu.class);
		myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
				| Intent.FLAG_ACTIVITY_NEW_TASK);
		myIntent.putExtra("TAGID", "SALES");
		startActivityForResult(myIntent, 0);
		finish();
	}
	
	
	private String getCurrentTimeStringCustom() {
		Calendar c = Calendar.getInstance();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String formattedDate = df.format(c.getTime());
		return formattedDate;
	}

	private String getCurrentTimeString() {
		// 2013-10-04 00:00:00.000
		Date dateNow = new Date();
		Calendar c = Calendar.getInstance();
		SimpleDateFormat ddMMMyyFormat = new SimpleDateFormat("dd/MM/yyyy");
		String date_to_string = ddMMMyyFormat.format(dateNow);
		return date_to_string;
	}
	
	private void currentuserTemp1() {
		// TODO Auto-generated method stub
		
		mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE, null);
		Cursor selectCurrentuserrec = null;
		try {
			selectCurrentuserrec = mydb.query(USER_SETTINGS, null, null, null,
					null, null, null);
		} catch (Exception e) {
		}
		if (selectCurrentuserrec != null) {
			if (selectCurrentuserrec.getCount() > 0) {
				while (selectCurrentuserrec.moveToNext()) {
					
					UserRouteCode = selectCurrentuserrec.getString(11);

					//String currentUserStRef = selectCurrentuserrec.getString(4);
					// Toast.makeText(getApplicationContext(),
					// "currentUserStRef :|"+currentUserStRef, 1).show();
					//if (currentUserStRef.equals("0") && TagId.equals(match)) {
						//etdmstorderno.setEnabled(false);
						// Toast.makeText(getApplicationContext(),
						// "itemTransType :", 1).show();
					//}

				}
			}
		}
		//latestInvoiceNumber();// Get current invoice temp
		selectCurrentuserrec.close();
		mydb.close();
	}
	
	@Override
	public void onBackPressed() {
		// Do Here what ever you want do on back press;
	}

			
}
